<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <title>Rails::Server</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <link rel="stylesheet" href="../../css/reset.css" type="text/css" media="screen" />
<link rel="stylesheet" href="../../css/main.css" type="text/css" media="screen" />
<link rel="stylesheet" href="../../css/github.css" type="text/css" media="screen" />
<script src="../../js/jquery-1.3.2.min.js" type="text/javascript" charset="utf-8"></script>
<script src="../../js/jquery-effect.js" type="text/javascript" charset="utf-8"></script>
<script src="../../js/main.js" type="text/javascript" charset="utf-8"></script>
<script src="../../js/highlight.pack.js" type="text/javascript" charset="utf-8"></script>

</head>

<body>     
    <div class="banner">
        
            <span>Ruby on Rails v4.0.0</span><br />
        
        <h1>
            <span class="type">Class</span> 
            Rails::Server 
            
                <span class="parent">&lt; 
                    
                    Rack::Server
                    
                </span>
            
        </h1>
        <ul class="files">
            
            <li><a href="../../files/railties/lib/rails/commands/server_rb.html">railties/lib/rails/commands/server.rb</a></li>
            
        </ul>
    </div>
    <div id="bodyContent">
        <div id="content">
  


  


  
  


  
    <!-- Namespace -->
    <div class="sectiontitle">Namespace</div>
    <ul>
      
        <li>
          <span class="type">CLASS</span>
          <a href="Server/Options.html">Rails::Server::Options</a>
        </li>
      
    </ul>
  


  
    <!-- Method ref -->
    <div class="sectiontitle">Methods</div>
    <dl class="methods">
      
        <dt>A</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="Server.html#method-i-app">app</a>
              </li>
            
          </ul>
        </dd>
      
        <dt>D</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="Server.html#method-i-default_options">default_options</a>
              </li>
            
          </ul>
        </dd>
      
        <dt>L</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="Server.html#method-i-log_path">log_path</a>
              </li>
            
          </ul>
        </dd>
      
        <dt>M</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="Server.html#method-i-middleware">middleware</a>
              </li>
            
          </ul>
        </dd>
      
        <dt>N</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="Server.html#method-c-new">new</a>
              </li>
            
          </ul>
        </dd>
      
        <dt>O</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="Server.html#method-i-opt_parser">opt_parser</a>
              </li>
            
          </ul>
        </dd>
      
        <dt>S</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="Server.html#method-i-set_environment">set_environment</a>,
              </li>
            
              
              <li>
                <a href="Server.html#method-i-start">start</a>
              </li>
            
          </ul>
        </dd>
      
    </dl>
  

  



  

    

    

    


    


    <!-- Methods -->
    
      <div class="sectiontitle">Class Public methods</div>
      
        <div class="method">
          <div class="title method-title" id="method-c-new">
            
              <b>new</b>(*)
            
            <a href="Server.html#method-c-new" name="method-c-new" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-c-new_source')" id="l_method-c-new_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/b0557389de13103c32baee438bf2d58f40176f73/railties/lib/rails/commands/server.rb#L40" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-c-new_source" class="dyn-source">
                <pre><span class="ruby-comment"># File railties/lib/rails/commands/server.rb, line 40</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">initialize</span>(*)
  <span class="ruby-keyword">super</span>
  <span class="ruby-identifier">set_environment</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
                  
      <div class="sectiontitle">Instance Public methods</div>
      
        <div class="method">
          <div class="title method-title" id="method-i-app">
            
              <b>app</b>()
            
            <a href="Server.html#method-i-app" name="method-i-app" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>TODO: this is no longer required but we keep it for the moment to support
older config.ru files.</p>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-app_source')" id="l_method-i-app_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/b0557389de13103c32baee438bf2d58f40176f73/railties/lib/rails/commands/server.rb#L46" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-app_source" class="dyn-source">
                <pre><span class="ruby-comment"># File railties/lib/rails/commands/server.rb, line 46</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">app</span>
  <span class="ruby-ivar">@app</span> <span class="ruby-operator">||=</span> <span class="ruby-keyword">begin</span>
    <span class="ruby-identifier">app</span> = <span class="ruby-keyword">super</span>
    <span class="ruby-identifier">app</span>.<span class="ruby-identifier">respond_to?</span>(<span class="ruby-value">:to_app</span>) <span class="ruby-operator">?</span> <span class="ruby-identifier">app</span>.<span class="ruby-identifier">to_app</span> <span class="ruby-operator">:</span> <span class="ruby-identifier">app</span>
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-default_options">
            
              <b>default_options</b>()
            
            <a href="Server.html#method-i-default_options" name="method-i-default_options" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-default_options_source')" id="l_method-i-default_options_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/b0557389de13103c32baee438bf2d58f40176f73/railties/lib/rails/commands/server.rb#L111" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-default_options_source" class="dyn-source">
                <pre><span class="ruby-comment"># File railties/lib/rails/commands/server.rb, line 111</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">default_options</span>
  <span class="ruby-keyword">super</span>.<span class="ruby-identifier">merge</span>({
    <span class="ruby-constant">Port</span><span class="ruby-operator">:</span>         <span class="ruby-number">3000</span>,
    <span class="ruby-constant">DoNotReverseLookup</span><span class="ruby-operator">:</span>  <span class="ruby-keyword">true</span>,
    <span class="ruby-identifier">environment</span><span class="ruby-operator">:</span>  (<span class="ruby-constant">ENV</span>[<span class="ruby-string">'RAILS_ENV'</span>] <span class="ruby-operator">||</span> <span class="ruby-constant">ENV</span>[<span class="ruby-string">'RACK_ENV'</span>] <span class="ruby-operator">||</span> <span class="ruby-string">&quot;development&quot;</span>).<span class="ruby-identifier">dup</span>,
    <span class="ruby-identifier">daemonize</span><span class="ruby-operator">:</span>    <span class="ruby-keyword">false</span>,
    <span class="ruby-identifier">debugger</span><span class="ruby-operator">:</span>     <span class="ruby-keyword">false</span>,
    <span class="ruby-identifier">pid</span><span class="ruby-operator">:</span>          <span class="ruby-constant">File</span>.<span class="ruby-identifier">expand_path</span>(<span class="ruby-string">&quot;tmp/pids/server.pid&quot;</span>),
    <span class="ruby-identifier">config</span><span class="ruby-operator">:</span>       <span class="ruby-constant">File</span>.<span class="ruby-identifier">expand_path</span>(<span class="ruby-string">&quot;config.ru&quot;</span>)
  })
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-log_path">
            
              <b>log_path</b>()
            
            <a href="Server.html#method-i-log_path" name="method-i-log_path" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-log_path_source')" id="l_method-i-log_path_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/b0557389de13103c32baee438bf2d58f40176f73/railties/lib/rails/commands/server.rb#L107" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-log_path_source" class="dyn-source">
                <pre><span class="ruby-comment"># File railties/lib/rails/commands/server.rb, line 107</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">log_path</span>
  <span class="ruby-node">&quot;log/#{options[:environment]}.log&quot;</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-middleware">
            
              <b>middleware</b>()
            
            <a href="Server.html#method-i-middleware" name="method-i-middleware" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-middleware_source')" id="l_method-i-middleware_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/b0557389de13103c32baee438bf2d58f40176f73/railties/lib/rails/commands/server.rb#L91" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-middleware_source" class="dyn-source">
                <pre><span class="ruby-comment"># File railties/lib/rails/commands/server.rb, line 91</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">middleware</span>
  <span class="ruby-identifier">middlewares</span> = []
  <span class="ruby-identifier">middlewares</span> <span class="ruby-operator">&lt;&lt;</span> [<span class="ruby-constant">Rails</span><span class="ruby-operator">::</span><span class="ruby-constant">Rack</span><span class="ruby-operator">::</span><span class="ruby-constant">Debugger</span>]  <span class="ruby-keyword">if</span> <span class="ruby-identifier">options</span>[<span class="ruby-value">:debugger</span>]
  <span class="ruby-identifier">middlewares</span> <span class="ruby-operator">&lt;&lt;</span> [<span class="ruby-operator">::</span><span class="ruby-constant">Rack</span><span class="ruby-operator">::</span><span class="ruby-constant">ContentLength</span>]

  <span class="ruby-comment"># FIXME: add Rack::Lock in the case people are using webrick.</span>
  <span class="ruby-comment"># This is to remain backwards compatible for those who are</span>
  <span class="ruby-comment"># running webrick in production. We should consider removing this</span>
  <span class="ruby-comment"># in development.</span>
  <span class="ruby-keyword">if</span> <span class="ruby-identifier">server</span>.<span class="ruby-identifier">name</span> <span class="ruby-operator">==</span> <span class="ruby-string">'Rack::Handler::WEBrick'</span>
    <span class="ruby-identifier">middlewares</span> <span class="ruby-operator">&lt;&lt;</span> [<span class="ruby-operator">::</span><span class="ruby-constant">Rack</span><span class="ruby-operator">::</span><span class="ruby-constant">Lock</span>]
  <span class="ruby-keyword">end</span>

  <span class="ruby-constant">Hash</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">middlewares</span>)
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-opt_parser">
            
              <b>opt_parser</b>()
            
            <a href="Server.html#method-i-opt_parser" name="method-i-opt_parser" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-opt_parser_source')" id="l_method-i-opt_parser_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/b0557389de13103c32baee438bf2d58f40176f73/railties/lib/rails/commands/server.rb#L53" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-opt_parser_source" class="dyn-source">
                <pre><span class="ruby-comment"># File railties/lib/rails/commands/server.rb, line 53</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">opt_parser</span>
  <span class="ruby-constant">Options</span>.<span class="ruby-identifier">new</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-set_environment">
            
              <b>set_environment</b>()
            
            <a href="Server.html#method-i-set_environment" name="method-i-set_environment" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-set_environment_source')" id="l_method-i-set_environment_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/b0557389de13103c32baee438bf2d58f40176f73/railties/lib/rails/commands/server.rb#L57" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-set_environment_source" class="dyn-source">
                <pre><span class="ruby-comment"># File railties/lib/rails/commands/server.rb, line 57</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">set_environment</span>
  <span class="ruby-constant">ENV</span>[<span class="ruby-string">&quot;RAILS_ENV&quot;</span>] <span class="ruby-operator">||=</span> <span class="ruby-identifier">options</span>[<span class="ruby-value">:environment</span>]
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-start">
            
              <b>start</b>()
            
            <a href="Server.html#method-i-start" name="method-i-start" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-start_source')" id="l_method-i-start_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/b0557389de13103c32baee438bf2d58f40176f73/railties/lib/rails/commands/server.rb#L61" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-start_source" class="dyn-source">
                <pre><span class="ruby-comment"># File railties/lib/rails/commands/server.rb, line 61</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">start</span>
  <span class="ruby-identifier">url</span> = <span class="ruby-node">&quot;#{options[:SSLEnable] ? 'https' : 'http'}://#{options[:Host]}:#{options[:Port]}&quot;</span>
  <span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;=&gt; Booting #{ActiveSupport::Inflector.demodulize(server)}&quot;</span>
  <span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;=&gt; Rails #{Rails.version} application starting in #{Rails.env} on #{url}&quot;</span>
  <span class="ruby-identifier">puts</span> <span class="ruby-string">&quot;=&gt; Run `rails server -h` for more startup options&quot;</span>
  <span class="ruby-identifier">trap</span>(<span class="ruby-value">:INT</span>) { <span class="ruby-identifier">exit</span> }
  <span class="ruby-identifier">puts</span> <span class="ruby-string">&quot;=&gt; Ctrl-C to shutdown server&quot;</span> <span class="ruby-keyword">unless</span> <span class="ruby-identifier">options</span>[<span class="ruby-value">:daemonize</span>]

  <span class="ruby-comment">#Create required tmp directories if not found</span>
  <span class="ruby-node">%w(cache pids sessions sockets)</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">dir_to_make</span><span class="ruby-operator">|</span>
    <span class="ruby-constant">FileUtils</span>.<span class="ruby-identifier">mkdir_p</span>(<span class="ruby-constant">File</span>.<span class="ruby-identifier">join</span>(<span class="ruby-constant">Rails</span>.<span class="ruby-identifier">root</span>, <span class="ruby-string">'tmp'</span>, <span class="ruby-identifier">dir_to_make</span>))
  <span class="ruby-keyword">end</span>

  <span class="ruby-keyword">unless</span> <span class="ruby-identifier">options</span>[<span class="ruby-value">:daemonize</span>]
    <span class="ruby-identifier">wrapped_app</span> <span class="ruby-comment"># touch the app so the logger is set up</span>

    <span class="ruby-identifier">console</span> = <span class="ruby-constant">ActiveSupport</span><span class="ruby-operator">::</span><span class="ruby-constant">Logger</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">$stdout</span>)
    <span class="ruby-identifier">console</span>.<span class="ruby-identifier">formatter</span> = <span class="ruby-constant">Rails</span>.<span class="ruby-identifier">logger</span>.<span class="ruby-identifier">formatter</span>
    <span class="ruby-identifier">console</span>.<span class="ruby-identifier">level</span> = <span class="ruby-constant">Rails</span>.<span class="ruby-identifier">logger</span>.<span class="ruby-identifier">level</span>

    <span class="ruby-constant">Rails</span>.<span class="ruby-identifier">logger</span>.<span class="ruby-identifier">extend</span>(<span class="ruby-constant">ActiveSupport</span><span class="ruby-operator">::</span><span class="ruby-constant">Logger</span>.<span class="ruby-identifier">broadcast</span>(<span class="ruby-identifier">console</span>))
  <span class="ruby-keyword">end</span>

  <span class="ruby-keyword">super</span>
<span class="ruby-keyword">ensure</span>
  <span class="ruby-comment"># The '-h' option calls exit before @options is set.</span>
  <span class="ruby-comment"># If we call 'options' with it unset, we get double help banners.</span>
  <span class="ruby-identifier">puts</span> <span class="ruby-string">'Exiting'</span> <span class="ruby-keyword">unless</span> <span class="ruby-ivar">@options</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">options</span>[<span class="ruby-value">:daemonize</span>]
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
                    </div>

    </div>
  </body>
</html>    